﻿
#include <stdio.h>
#include <stdlib.h>
#include <string.h>

#include "log.h"
#include "toolfun.h"
#include "haskelltool.h"
#include "barcode.h"

#include <algorithm>
#include <vector>
#include <functional>
#include <iostream>
#include <iomanip>
//typedef std::function< int(share_zone_t&, share_queue_t&, share_grid_t &)> GridFunType;
#define     Min(a,b)    (a) < (b)? (a) : (b)
//typedef std::function< int(int, int)> zipFunT;
void logInfoP(const char *fmt, ...);

template <typename T>
static  std::vector<T> zipWith(std::function< T(T, T)> fun,  std::vector<T>& list1, std::vector<T> &list2)
{
    int size = std::min(list1.size(), list2.size());
    std::vector<T> resultList;
    for(int i = 0; i < size; i++)
    {
        T result = fun(list1[i], list2[i]);
        resultList.push_back(result);
       // logInfo("%f+%f=%f", list1[i], list2[i], result);
    }
    return resultList;
}
template <typename T>
static T add(T x1, T x2)
{
    return x1 + x2;
}

template <typename T>
static T diff(T x1, T x2)
{
    return x1 - x2;
}


template <typename T>
static  void printVector( std::vector<T> list, const char *prestr)
{
    std::cerr <<prestr<<"[ ";
    //logInfoP("%s[ ", prestr);
    for(int i = 0; i < list.size(); i++)
    {
        //logInfoP("%d ", list[i]);
        std::cerr<<list[i]<<" ";
    }
    std::cerr<<"]\n";

}
int testfun1()
{
    logInfo("***************BarCode**4***********");

    //================================================================
    std::vector<int> x1 {1,2,3,4};
    std::vector<int> x2{100,1000,100,1000};
    printVector<int>(x1, "x1");
    printVector<int>(x2, "x2");

    std::vector<int> list1 = zipWith<int>(add<int>,x1,x2);
    printVector<int>(list1, "result add");

    std::vector<int> list2 = zipWith<int>(diff<int>,x1,x2);
    printVector<int>(list2, "result diff");
    //================================================================
    std::vector<double> y1 {31.1,2.1,3.1,4.1};
    std::vector<double> y2{200.5,2000.6,200.7,2000.8};

    printVector<double>(y1, "y1");
    printVector<double>(y2, "y2");

    std::vector<double> list11 = zipWith<double>(add<double>,y1,y2);
    printVector<double>(list11, "result add");

    std::vector<double> list12 = zipWith<double>(diff<double>,y1,y2);
    printVector<double>(list12, "result diff");
    //================================================================
    //================================================================
    //================================================================
    //================================================================
    //================================================================
    //================================================================



    return 0;
}
static std::string complement (std::string &str)
{
    std::string str2;
    char c;

    for (int i = 0; i < str.length(); i++)
    {
        if (str[i] == '0')
        {
            c = '1';
        }
        else
        {
            c = '0';
        }
    }

    return str2;
}
int main_barcode4()
{
    testfun1();
    std::vector<std::string> leftOddList
    {"0001101", "0011001", "0010011", "0111101", "0100011",
    "0110001", "0101111", "0111011", "0110111", "0001011"};




    return 0;

}
